package com.zzyl.nursing.mapper;

import java.time.LocalDateTime;
import java.util.List;
import com.zzyl.nursing.domain.Reservation;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zzyl.nursing.dto.ReservationMemberAddDto;
import com.zzyl.nursing.vo.CountByTimeVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * 预约信息Mapper接口
 * 
 * @author ruoyi
 * @date 2025-08-28
 */
@Mapper
public interface ReservationMemberMapper extends BaseMapper<Reservation>
{
    /**
     * 查询预约信息
     * 
     * @param id 预约信息主键
     * @return 预约信息
     */
    public Reservation selectReservationById(Long id);


    /**
     * 新增预约信息
     * 
     * @param dto 预约信息
     * @return 结果
     */
    public void insertReservation( ReservationMemberAddDto dto);

    /**
     * 更新预约状态
     * @param reservation 预约信息
     * @return 结果
     */
    public int updateReservation(Reservation reservation);

    /**
     * 删除预约信息
     * 
     * @param id 预约信息主键
     * @return 结果
     */
    public int deleteReservationById(Long id);

    /**
     * 批量删除预约信息
     * 
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteReservationByIds(Long[] ids);

    /**
     * 根据用户ID获取当天取消预约次数
     * @param userId 用户ID
     * @return 取消预约次数
     */
    @Select("select COUNT(*) from reservation where status = 2 and update_by = #{userId} and DATE(create_time) = CURDATE()")
    Integer cancelledCount(@Param("userId") Long userId);

    /**
     * 查询每个时间段剩余预约次数
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @return List<CountByTimeVo>
     */
    List<CountByTimeVo> countReservationsForTime(@Param("startTime") LocalDateTime startTime, @Param("endTime") LocalDateTime endTime);

    /**
     * 查询预约登记列表
     *
     * @param reservation 预约登记
     * @return 预约登记集合
     */
    public List<Reservation> selectReservationList(Reservation reservation);

    /**
     * 取消预约,将状态改为已取消
     * @param id 预约ID
     */
    @Update("update reservation set status = 2 where id = #{id}")
    void cancel(Long id);



}
